package com.linkhub.oms.admin.modules.user.account.domain.vo;

import com.linkhub.oms.common.util.QtBigDecimalUtil;
import com.linkhub.oms.entity.UserAccountEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * 用户账户信息VO
 *
 * @author Frank
 */
@Data
@ApiModel("用户账户信息VO")
@AllArgsConstructor
public class UserAccountVO implements Serializable {
    private final static String DEFAULT_BALANCE = "0.00";
    @ApiModelProperty(value = "总金额")
    private String totalBalance;

    @ApiModelProperty(value = "可用金额")
    private String availableBalance;

    @ApiModelProperty(value = "冻结金额")
    private String frozenBalance;

    public UserAccountVO() {
        this.totalBalance = DEFAULT_BALANCE;
        this.availableBalance = DEFAULT_BALANCE;
        this.frozenBalance = DEFAULT_BALANCE;
    }

    public UserAccountVO(UserAccountEntity userAccountEntity) {
        this.totalBalance = QtBigDecimalUtil.toString(userAccountEntity.getTotalBalance());
        //总金额-冻结金额
        this.availableBalance = QtBigDecimalUtil.toString(userAccountEntity.getTotalBalance()
                .subtract(userAccountEntity.getFrozenBalance()));
        this.frozenBalance = QtBigDecimalUtil.toString(userAccountEntity.getFrozenBalance());
    }
}
